package cn.itcast.haa.config;

import cn.itcast.haa.tool.AmapTool;
// 移除不需要的导入
import cn.itcast.haa.tool.SinaTool;
import cn.itcast.haa.tool.ToutiaoTool;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类
 *
 * @Author mr.wu
 * @Date 2025-11-7 15:09
 */
@Configuration
public class CommonConfig {

    @Bean
    public ChatMemory chatMemory(){
        return MessageWindowChatMemory.builder().build();
    }

    @Bean
    public ChatClient chatClient(DashScopeChatModel chatModel, ChatMemory chatMemory, ToutiaoTool toutiaoTool, SinaTool sinaTool, AmapTool amapTool) {
        return ChatClient.builder(chatModel)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
                .defaultTools(toutiaoTool, sinaTool, amapTool)
                .build();
    }
}
